<template>
    <div>
        <el-table :data="tableData" border stripe style="width: 100%">
            <el-table-column type="selection" width="40" align="center"></el-table-column>
            <el-table-column fixed type="index" label="序号" width="50" align="center" :index="indexMethod"></el-table-column>
            <el-table-column label="申请人" align="center" show-overflow-tooltip>
                <template slot-scope="slot">
                    {{ GetNameByUserId(slot.row.OperatId) }}
                </template>
            </el-table-column>
            <el-table-column label="调入项目" align="center" show-overflow-tooltip>
                <template slot-scope="slot">
                    {{ GetProjectNameById(slot.row.TransferPoject) }}
                </template>
            </el-table-column>
            <el-table-column label="调入项目工作内容" align="center" prop="TransferPojectContent" show-overflow-tooltip></el-table-column>
            <el-table-column label="申请日期" align="center" show-overflow-tooltip>
                <template slot-scope="slot">
                    {{ fmtDate(slot.row.ApplyDate) }}
                </template>
            </el-table-column>
            <el-table-column label="到岗日期" align="center" show-overflow-tooltip>
                <template slot-scope="slot">
                    {{ fmtDate(slot.row.ArriveDate) }} 
                </template>
            </el-table-column>
            <el-table-column label="调动原因" align="center" prop="Reason" show-overflow-tooltip></el-table-column>
            <el-table-column fixed="right" label="操作" align="center" width="120">
                <template slot-scope="slot">
                    <el-button type="success" size="mini" plain @click="ShowpersonneltransferTable(slot.row)">报表</el-button>
                </template>
            </el-table-column>
        </el-table>

        <el-dialog :visible.sync="ProjectpersonneltransferTableTwo_dialog.show" width="100%" top="0vh" title="项目人员调动报表" :modal="false">
            <ProjectpersonneltransferTableTwo :project="project" :project-people-device-transfer="ProjectpersonneltransferTableTwo_dialog.data"></ProjectpersonneltransferTableTwo>
        </el-dialog>

    </div>
</template>

<script>
    import ProjectpersonneltransferTableTwo from "./ProjectpersonneltransferTableTwo";
    import * as publicjs from "../../../../public/Scriput/Public";

    export default {
        name: "ProjectpersonneltransferTable",
        components:{
            ProjectpersonneltransferTableTwo
        },
        props:{
            project:{
                type:Object,
                required:true,
            }
        },
        data(){
            return{
                tableData:[],
                AllCompanyAllUsers:[],
                AllProject:[],
                ProjectpersonneltransferTableTwo_dialog:{
                    show:false,
                    data:{},
                }
            }
        },
        watch:{
            project:function () {
                this.Init()
                this.GetData()
            }
        },
        mounted() {
            let _this = this
            this.$nextTick(()=>{
                _this.Init()
                _this.GetData()
            })
        },
        methods:{
            Init(){
                this.AllCompanyAllUsers = publicjs.GetCompanyAllUsers(this.$http)
                this.AllProject = publicjs.GetAllProject(this.$http)
                // this.GetProjectDevice = publicjs.GetProjectDevice(this.$http,this.project.Id)
                // this.AllProjectPeople = publicjs.GetProjectPeople(this.$http,this.project.Id)
                // this.AllFinanceCategory = publicjs.GetAllFinanceCategory(this.$http)
            },
            //表格数据序列号
            indexMethod(index) {
                return index + 1
            },
            //数据转换
            fmtDate(val){
                if (val!=null&&val!=''){
                    return val.split(' ')[0]
                }else{
                    return ''
                }
            },
            //根据userid获取userName,主要用于公司人员
            GetNameByUserId(UserId){
                for (let i=0;i<this.AllCompanyAllUsers.length;i++){
                    if (this.AllCompanyAllUsers[i].Id == UserId){
                        return this.AllCompanyAllUsers[i].UserName
                    }
                }
            },
            //根据id获取Name,主要用于项目名称
            GetProjectNameById(Id){
                for (let i=0;i<this.AllProject.length;i++){
                    if (this.AllProject[i].Id == Id){
                        return this.AllProject[i].ProjectName
                    }
                }
            },
            //数据获取
            GetData(){
                this.$http.post('Project1/GetAllProjectDeviceTransferData',{
                    ProjectId: this.project.Id,
                    Type:1
                }).then(res=>{
                    console.log(res.data)
                    this.tableData = res.data;
                })
            },
            //报表
            ShowpersonneltransferTable(obj){
                this.ProjectpersonneltransferTableTwo_dialog.data=obj
                this.ProjectpersonneltransferTableTwo_dialog.show=true
            }
        }
    }
</script>

<style scoped>

</style>
